package cn.com.blog.web.controller.rest;/**
 * Created by IntelliJ IDEA.
 * User: Yangdx.
 * Date: 2017/4/13.
 * Time: 11:57.
 * Tags: Code, we are serious.
 */

import cn.com.blog.domain.Article;
import cn.com.blog.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户注册请求
 *
 * @author yangdx
 * @create 2017-04-13 11:57
 **/
@SuppressWarnings("ALL")
@RestController
@RequestMapping(
        value = {"/blog/article"},
        produces = {"application/json;charset=UTF-8"}
)
public class ArticleController {
    private Logger logger = LoggerFactory.getLogger(ArticleController.class);
    @Resource
    private ArticleService articleService;

    /**
     * 分页查询
     * @param user
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/findPage")
    @ResponseBody
    public ModelAndView findPage(Model model, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        try {
            PageHelper.startPage(pageNum,pageSize);
            List<Article> articleList = articleService.selectAll();
            PageInfo pageInfo = new PageInfo(articleList);
            model.addAttribute("articleList", pageInfo);
            return new ModelAndView("client/index");
        } catch (Exception e) {
            this.logger.error("分页查询, 出现异常={}", e.getMessage(), e);
            return null;
        }
    }
}
